/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.pojo;

import java.sql.ResultSet;
import java.util.ArrayList;

import models.util.MySqlDataAccessHelper;

/**
 * 
 * @author KimLien
 */

public class StProduct {
	private static final long serialVersionUID = 1L;
	
	private String productID;

	private String storeID;

	private String proTypeID;

	private String manufacturerID;

	private String productName;

	private Integer unitID;

	private String origin;

	private Integer taxID;

	private Double inventoryMin;

	private String image;

	private Double purchaseprice;

	private Double retailprice;

	private Double wholesale;

	private Integer currencyID;
	
	private String nameCurrency;

//	private Date dateImport;
//
//	private Date dateExport;
//
//	private Boolean isImport;
	private double soluongchoxuat=0;
	private double soluongchonhap=0;
	
	public StProduct(boolean selected,String productID, String storeID, String proTypeID,String manufacturerID,
			String productName, Integer unitID, String origin, Integer taxID, Double inventoryMax,
			Double inventoryMin, Double quantity, String image, Double purchaseprice, Double retailprice,
			Double wholesale,Integer currencyID, boolean active,String nameCurrency){
		this.selected = selected;
		this.productID = productID;
		this.storeID = storeID;
		this.proTypeID = proTypeID;
		this.manufacturerID = manufacturerID;
		this.productName = productName;
		this.unitID = unitID;
		this.origin = origin;
		this.taxID = taxID;
		this.inventoryMax = inventoryMax;
		this.inventoryMin = inventoryMin;
		this.quantity = quantity;
		this.image = image;
		this.purchaseprice = purchaseprice;
		this.retailprice = retailprice;
		this.wholesale = wholesale;
		this.currencyID = currencyID;
		this.active = active;
		this.nameCurrency = nameCurrency;
	}
		
	public double getSoluongchoxuat() {
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();
		try {
			mysql.open();
			String sql="select sum(st_exvoucherdetail.Quantity) as soluongchoxuat " +
					"from st_exvoucherdetail,st_exvoucher " +
					"where st_exvoucher.VoucherID=st_exvoucherdetail.EXVoucherID " +
					"and st_exvoucher.`Status`=0 " +
					"and st_exvoucherdetail.ProductID='"+this.productID+"' " +
					"group by st_exvoucherdetail.ProductID;";
			ResultSet rs = mysql.executeQuery(sql);
			if(rs.next()){
				soluongchoxuat=rs.getDouble("soluongchoxuat");
			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			mysql.close();
		}
		return soluongchoxuat;
	}

	public void setSoluongchoxuat(double soluongchoxuat) {
		this.soluongchoxuat = soluongchoxuat;
	}

	public double getSoluongchonhap() {
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();
		try {
			mysql.open();
			String sql="select sum(st_imvoucherdetail.Quantity) as soluongchonhap " +
					"from st_imvoucherdetail,st_imvoucher " +
					"where st_imvoucher.VoucherID=st_imvoucherdetail.IMVoucherID " +
					"and st_imvoucher.`Status`=0 " +
					"and st_imvoucherdetail.ProductID='"+this.productID+"' " +
					"group by st_imvoucherdetail.ProductID;";
			ResultSet rs = mysql.executeQuery(sql);
			while(rs.next()){
				soluongchonhap=rs.getDouble("soluongchonhap");
			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			mysql.close();
		}
		return soluongchonhap;
	}

	public void setSoluongchonhap(double soluongchonhap) {
		this.soluongchonhap = soluongchonhap;
	}


	private Boolean active;

	private StStore store;
	private boolean select;
	
	public boolean isSelect() {
		return select;
	}

	public void setSelect(boolean select) {
		this.select = select;
	}


	private String valueComboIDPro = "";
	private String valueComboProName = "";
	private String valueComboStore = "";
	private int valueComboUnit;
	private int key;
	
	private ArrayList<StStore> allStore = new ArrayList<StStore>();
	private ArrayList<StProducttype> allProType = new ArrayList<StProducttype>();
	private ArrayList<StManufacturer> allManufacturer = new ArrayList<StManufacturer>();
	private ArrayList<AcUnit> allUnit = new ArrayList<AcUnit>();
	private ArrayList<AcTax> allTax = new ArrayList<AcTax>();
	private ArrayList<StCurrency> allCurency = new ArrayList<StCurrency>();
		
	public StProduct() {
		valueComboIDPro = "";
		valueComboProName = "";
		valueComboStore = "";
	}

	public int getKey() {
		return key;
	}

	public void setKey(int key) {
		this.key = key;
	}

	

	public StProduct(String productID) {
		this.productID = productID;
	}

	public String getProductID() {
		return productID;
	}

	public void setProductID(String productID) {
		this.productID = productID;
	}

	public String getStoreID() {
		return storeID;
	}

	public void setStoreID(String storeID) {
		this.storeID = storeID;
	}

	public String getProTypeID() {
		return proTypeID;
	}

	public void setProTypeID(String proTypeID) {
		this.proTypeID = proTypeID;
	}

	public String getManufacturerID() {
		return manufacturerID;
	}

	public void setManufacturerID(String manufacturerID) {
		this.manufacturerID = manufacturerID;
	}

	public String getProductName() {
		return productName;
	}

	public void setProductName(String productName) {
		this.productName = productName;
	}

	public Integer getUnitID() {
		return unitID;
	}

	public void setUnitID(Integer unitID) {
		this.unitID = unitID;
	}

	public String getOrigin() {
		return origin;
	}

	public void setOrigin(String origin) {
		this.origin = origin;
	}

	public Integer getTaxID() {
		return taxID;
	}

	public void setTaxID(Integer taxID) {
		this.taxID = taxID;
	}

	public Double getInventoryMin() {
		return inventoryMin;
	}

	public void setInventoryMin(Double inventoryMin) {
		this.inventoryMin = inventoryMin;
	}

	public String getImage() {
		return image;
	}

	public void setImage(String image) {
		this.image = image;
	}

	public Double getPurchaseprice() {
		return purchaseprice;
	}

	public void setPurchaseprice(Double purchaseprice) {
		this.purchaseprice = purchaseprice;
	}

	public Double getRetailprice() {
		return retailprice;
	}

	public void setRetailprice(Double retailprice) {
		this.retailprice = retailprice;
	}

	public Double getWholesale() {
		return wholesale;
	}

	public void setWholesale(Double wholesale) {
		this.wholesale = wholesale;
	}

	public Integer getCurrencyID() {
		return currencyID;
	}

	public void setCurrencyID(Integer currencyID) {
		this.currencyID = currencyID;
	}

//	public Date getDateImport() {
//		return dateImport;
//	}
//
//	public void setDateImport(Date dateImport) {
//		this.dateImport = dateImport;
//	}
//
//	public Date getDateExport() {
//		return dateExport;
//	}
//
//	public void setDateExport(Date dateExport) {
//		this.dateExport = dateExport;
//	}
//
//	public Boolean getIsImport() {
//		return isImport;
//	}
//
//	public void setIsImport(Boolean isImport) {
//		this.isImport = isImport;
//	}

	
	public ArrayList<StStore> getAllStore() {
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();
		try {
			mysql.open();
			allStore.clear();
//			String sql="select * from "
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			
		}
		return allStore;
	}

	public Boolean getActive() {
		return active;
	}

	public void setActive(Boolean active) {
		this.active = active;
	}

	public void setAllStore(ArrayList<StStore> allStore) {
		this.allStore = allStore;
	}

	public ArrayList<StProducttype> getAllProType() {
		return allProType;
	}

	public void setAllProType(ArrayList<StProducttype> allProType) {
		this.allProType = allProType;
	}

	public ArrayList<StManufacturer> getAllManufacturer() {
		return allManufacturer;
	}

	public void setAllManufacturer(ArrayList<StManufacturer> allManufacturer) {
		this.allManufacturer = allManufacturer;
	}

	public ArrayList<AcUnit> getAllUnit() {
		return allUnit;
	}

	public void setAllUnit(ArrayList<AcUnit> allUnit) {
		this.allUnit = allUnit;
	}

	public ArrayList<AcTax> getAllTax() {
		return allTax;
	}

	public void setAllTax(ArrayList<AcTax> allTax) {
		this.allTax = allTax;
	}

	public ArrayList<StCurrency> getAllCurency() {
		return allCurency;
	}

	public void setAllCurency(ArrayList<StCurrency> allCurency) {
		this.allCurency = allCurency;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public StStore getStore() {
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();
		try {
			mysql.open();
			String sql="select * from st_store where StoreID='"+this.getStoreID()+"'";
			ResultSet rs = mysql.executeQuery(sql);
			while(rs.next()){
				store=new StStore();
				store.setStoreName(rs.getString("Store_Name"));
			}
			rs.close();
		} catch (Exception e) {
			
		}finally{
			mysql.close();
		}
		return store;
	}

	public void setStore(StStore store) {
		this.store = store;
	}

	public String getValueComboIDPro() {
		return valueComboIDPro;
	}

	public void setValueComboIDPro(String valueComboIDPro) {
		this.valueComboIDPro = valueComboIDPro;
	}

	public String getValueComboProName() {
		return valueComboProName;
	}

	public void setValueComboProName(String valueComboProName) {
		this.valueComboProName = valueComboProName;
	}

	public String getValueComboStore() {
		return valueComboStore;
	}

	public void setValueComboStore(String valueComboStore) {
		this.valueComboStore = valueComboStore;
	}


	///////////////////////
	private  boolean selected;

	private double quantity;
	private Double inventoryMax;
	
	private StCurrency currencyinfo;
	
	private StProducttype protypeinfo;
    
    private StStore storeinfo;
    
    private AcUnit unitinfo;
    
    private AcTax taxinfo;
    
    private AcCustomer manufactureinfo;

	public StProducttype getProtypeinfo() {
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();
		
		try {
			mysql.open();
			String sql = "select * from st_producttype where ProductTypeID='"+this.proTypeID+"'";
			ResultSet rs = mysql.executeQuery(sql);
			while (rs.next()) {
				protypeinfo = new StProducttype();
				protypeinfo.setProductTypeID(rs.getString("ProductTypeID"));
				protypeinfo.setProductTypeName(rs.getString("ProductTypeName"));
			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			mysql.close();
		}
		return protypeinfo;
	}

	public void setProtypeinfo(StProducttype protypeinfo) {
		this.protypeinfo = protypeinfo;
	}

	public StStore getStoreinfo() {
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();
		
		try {
			mysql.open();
			String sql = "select * from st_store where StoreID='"+this.storeID+"'";
			ResultSet rs = mysql.executeQuery(sql);
			while (rs.next()) {
				storeinfo = new StStore();
				storeinfo.setStoreID(rs.getString("StoreID"));
				storeinfo.setStoreName(rs.getString("Store_Name"));
			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			mysql.close();
		}
		return storeinfo;
	}

	public void setStoreinfo(StStore storeinfo) {
		this.storeinfo = storeinfo;
	}

	public AcUnit getUnitinfo(String lang) {
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();
		
		try {
			mysql.open();
			String sql = "select * from ac_unit,ac_unit_lang where ac_unit.UnitID=ac_unit_lang.UnitID and ac_unit_lang.LangID='"+lang+"' and ac_unit.UnitID="+this.unitID;
			ResultSet rs = mysql.executeQuery(sql);
			while (rs.next()) {
				unitinfo = new AcUnit();
				unitinfo.setUnitId(rs.getInt("UnitID"));
				unitinfo.setUnitName(rs.getString("UnitName"));
			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			mysql.close();
		}
		return unitinfo;
	}

	public void setUnitinfo(AcUnit unitinfo) {
		this.unitinfo = unitinfo;
	}

	public AcTax getTaxinfo(String lang) {
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();
		
		try {
			mysql.open();
			String sql = "select * from ac_tax,ac_tax_lang " +
					"where ac_tax.TaxID=ac_tax_lang.TaxID " +
					"and ac_tax_lang.LangID='"+lang+"' " +
							"and ac_tax.TaxID="+this.taxID;
			ResultSet rs = mysql.executeQuery(sql);
			while (rs.next()) {
				taxinfo = new AcTax();
				taxinfo.setTaxId(rs.getInt("TaxID"));
				taxinfo.setTaxName(rs.getString("TaxName"));
			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			mysql.close();
		}
		return taxinfo;
	}

	public void setTaxinfo(AcTax taxinfo) {
		this.taxinfo = taxinfo;
	}

	public AcCustomer getManufactureinfo() {
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();
		
		try {
			mysql.open();
			String sql = "select * from ac_customer where CustomerID='"+this.manufacturerID+"'";
			ResultSet rs = mysql.executeQuery(sql);
			while (rs.next()) {
				manufactureinfo = new AcCustomer();
				manufactureinfo.setCustomerId(rs.getString("CustomerID"));
				manufactureinfo.setCustomerName(rs.getString("CustomerName"));
			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			mysql.close();
		}
		return manufactureinfo;
	}

	public void setManufactureinfo(AcCustomer manufactureinfo) {
		this.manufactureinfo = manufactureinfo;
	}



	public StCurrency getCurrencyinfo() {
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();
		
		try {
			mysql.open();
			String sql = "select * from st_currency where CurrencyID="+this.currencyID;
			ResultSet rs = mysql.executeQuery(sql);
			while (rs.next()) {
				currencyinfo = new StCurrency();
				currencyinfo.setCurrencyID(rs.getInt("CurrencyID"));
				currencyinfo.setCurrencyName(rs.getString("CurrencyrName"));
			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			mysql.close();
		}
		return currencyinfo;
	}

	public void setCurrencyinfo(StCurrency currencyinfo) {
		this.currencyinfo = currencyinfo;
	}

	public boolean isSelected() {
		return selected;
	}

	public void setSelected(boolean selected) {
		this.selected = selected;
	}

	public double getQuantity() {
		return quantity;
	}

	public void setQuantity(double quantity) {
		this.quantity = quantity;
	}

	public Double getInventoryMax() {
		return inventoryMax;
	}

	public void setInventoryMax(Double inventoryMax) {
		this.inventoryMax = inventoryMax;
	}
    
    

	public int getValueComboUnit() {
		return valueComboUnit;
	}

	public void setValueComboUnit(int valueComboUnit) {
		this.valueComboUnit = valueComboUnit;
	}
	public StProduct(Boolean select,String productID,String productName){
		this.select=select;
		this.productID=productID;
		this.productName=productName;
	}
	public StProduct(Boolean select,String productID,String productName,String proTypeID,String manu){
		this.select=select;
		this.productID=productID;
		this.productName=productName;
		this.proTypeID=proTypeID;
		this.manufacturerID=manu;
	}

	public void setNameCurrency(String nameCurrency) {
		this.nameCurrency = nameCurrency;
	}

	public String getNameCurrency() {
		return nameCurrency;
	}

}
